import axios from './axios'
import qs from 'qs'

//获取供应商列表
export function getVendorList(belongModule='') {
    return axios.post('/supplier/manage/get_supplier_list.do?belongModule=' + belongModule).then(res => Promise.resolve(res.data))
}

//新增供应商
export function addVendor({chineseName, englishName,supplierCode,belongModule}) {
    return axios.post('/supplier/manage/add_supplier.do', qs.stringify({
        chineseName,
        englishName,
        supplierCode,
        belongModule
    })).then(res => Promise.resolve(res.data))
}

//修改供应商
export function modVendor({id, chineseName, englishName,supplierCode,belongModule}) {
    return axios.post('/supplier/manage/update_supplier.do', qs.stringify({
        id,
        chineseName,
        englishName,
        supplierCode,
        belongModule
    })).then(res => Promise.resolve(res.data))
}

//供应商地址列表
export function vendorAddressList(supplierId) {
    return axios.post('/supplier/manage/show_supplier_address_list.do',
        qs.stringify({supplierId})).then(res => Promise.resolve(res.data), err => Promise.reject(err))
}

//供应商地址增加
export function addVendorAddress({supplierId, supplierAddress, supplierAddressAbbr, longitude, latitude}) {
    const data = qs.stringify({supplierId, supplierAddress, supplierAddressAbbr, longitude, latitude});
    return axios.post('/supplier/manage/add_supplier_address.do', data).then(res => Promise.resolve(res.data))
}

//供应商地址修改
export function modVendorAddress({id, supplierId, supplierAddress, supplierAddressAbbr, longitude, latitude}) {
    const data = qs.stringify({id, supplierId, supplierAddress, supplierAddressAbbr, longitude, latitude});
    return axios.post('/supplier/manage/update_supplier_address.do', data).then(res => Promise.resolve(res.data))
}

//供应商联系人
export function vendorContactList(supplierId) {
    return axios.post('/supplier/manage/show_supplier_contact_list.do',
        qs.stringify({supplierId})).then(res => Promise.resolve(res.data))
}

//新增供应商联系人
export function addVendorContact({supplierId, supplierContact, email, jobPosition, sex, phones}) {
    const data = qs.stringify({supplierId, supplierContact, email, jobPosition, sex, phones});
    return axios.post('/supplier/manage/add_supplier_contact.do', data).then(res => Promise.resolve(res.data))
}

//修改供应商联系人
export function modVendorContact({id, supplierId, supplierContact, email, jobPosition, sex, phones}) {
    const data = qs.stringify({id, supplierId, supplierContact, email, jobPosition, sex, phones});
    return axios.post('/supplier/manage/update_supplier_contact.do', data).then(res => Promise.resolve(res.data))
}

//采购合同
export function purchaseContact(status) {
    return axios.post('/jianzhan_import_and_export/manage/show_purchase_contract_list.do', qs.stringify({status})).then(res => Promise.resolve(res.data))
}

//采购合同新增
export function addPurchaseContract(contract) {
    const data = qs.stringify(contract);
    return axios.post('/jianzhan_import_and_export/manage/add_purchase_contract.do', data).then(res => Promise.resolve(res.data))
}

//采购合同修改
export function modPurchaseContract(contract) {
    const data = qs.stringify(contract);
    return axios.post('/jianzhan_import_and_export/manage/update_purchase_contract.do', data).then(res => Promise.resolve(res.data))
}

//发运列表
export function deliveryList(status) {
    return axios.post('/jianzhan_import_and_export/manage/show_send_goods_list.do', qs.stringify({status})).then(res => Promise.resolve(res.data))
}

//增加发运
export function addDelivery(ship) {
    const data = qs.stringify(ship);
    return axios.post('/jianzhan_import_and_export/manage/add_send_goods.do', data).then(res => Promise.resolve(res.data))
}

//修改发运
export function modDelivery(ship) {
    const data = qs.stringify(ship);
    return axios.post('/jianzhan_import_and_export/manage/update_send_goods.do', data).then(res => Promise.resolve(res.data))
}



//进出口
export function exportList() {
    return axios.get('/jianzhan_import_and_export/manage/show_export_list.do').then(res => Promise.resolve(res.data))
}

export function addExport(exp) {
    return axios.post('/jianzhan_import_and_export/manage/save_spare_parts_export.do', qs.stringify(exp)).then(res => Promise.resolve(res.data));
}

export function modExport(exp) {
    return axios.post('/jianzhan_import_and_export/manage/update_spare_parts_export.do', qs.stringify(exp)).then(res => Promise.resolve(res.data))
}


//获得船的信息
export function getShipInfo() {
    return axios.get('/jianzhan_import_and_export/manage/show_jianzhan_ship_list.do').then(res => Promise.resolve(res.data))
}

export function shipDetail(shipInformation) {
    return axios.post('/jianzhan_import_and_export/manage/select_by_jianzhan_ship.do', qs.stringify({shipInformation})).then(res => Promise.resolve(res.data))
}

export function getPurchaseList() {
    return axios.get('/purchase_requisition/manage/show_purchase_list.do').then(res => Promise.resolve(res.data))
}



//jianzhan添加销售单
export function addPurchase(purchase) {
    return axios.post('/purchase_requisition/manage/save_purchase_requisition.do', qs.stringify(purchase)).then(res => Promise.resolve(res.data))
}
//jianzhan修改销售单
export function modPurchase(purchase) {
    return axios.post('/purchase_requisition/manage/update_purchase_requisition.do', qs.stringify(purchase)).then(res => Promise.resolve(res.data))
}



//根据发运合同id获取供应商列表
export function getVendorByDeliveryContractId(purchaseContractNumberId) {
    return axios.post('/jianzhan_import_and_export/manage/show_supplier_by_id.do', qs.stringify({purchaseContractNumberId})).then(res => Promise.resolve(res.data))
}


//根据发运合同计算总箱数
export function getTotalBox(freightList) {
    return axios.post('/jianzhan_import_and_export/manage/sum_total_box.do',qs.stringify({freightList})).then(res=>Promise.resolve(res.data))
}

//剑展cost
export function getCost() {
    return axios.get('/jianzhan_import_and_export/manage/show_invoice.do').then(res=>Promise.resolve(res.data))
}